package job.sxf;
import java.util.*;

public class sxf4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t1 = in.nextInt();
        for (int c = 0; c < t1; c++){
            int n = in.nextInt();
            int k = in.nextInt();
            int[] t = new int[n];
            int[] tt = new int[n];
            for (int i = 0; i < n; i++){
                t[i] = in.nextInt();
                tt[i] = t[i];
            }
            Arrays.sort(t);
            int mink = t[k-1];
            for (int i = 0; i < n; i++){
                if (tt[i] > mink) tt[i] = 0;
            }
            int sum = 0;
            for (int i = 0; i < k; i++){
                sum += t[i];
            }
            int minabs = Integer.MAX_VALUE;
            int sum1 = 0;
            for (int i = 0; i < n; i++){
                sum1 += tt[i];
                if (Math.max(sum1, (sum - sum1)) < minabs){
                    minabs = Math.max(sum1, (sum - sum1));
                }
            }
            System.out.println(minabs);
        }
    }
}
